IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GetIDSISProtocolUpdates]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[GetIDSISProtocolUpdates]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO

/****** Object:  StoredProcedure [dbo].[GetIDSISProtocolUpdates]    Script Date: 11/19/2008 19:17:28 ******/

/************************************************************************************************
* Name:		GetIDSISProtocolUpdates
* Purpose:	Stored procedure for getting queued protocols which need to be sent to IDSIS
*               for updating their system.  Used by the Humans web service::NotifyIDSIS()
* PARAMETERS  
*	Name			Description
* -------------------------	-----------------------------
* @protocolId			Whether to return those records requiring only a pending change 
*				notification.  If false, it returns protocols where the status has
*				changed, so the entire protocol data needs to be sent.
************************************************************************************************/
CREATE PROCEDURE [dbo].[GetIDSISProtocolUpdates]
(@notifications bit = 0)
AS
BEGIN
	SET NOCOUNT ON;
	if ( @notifications = 1 )
	BEGIN
		SELECT * FROM Stg_IDSISProtocolUpdates
		WHERE StatusChange is null
	END
	ELSE
	BEGIN
		SELECT * FROM Stg_IDSISProtocolUpdates
		WHERE isnull(StatusChange, 0) = 1
	END
END

GO